\section{Calculus}

\subsection{Derivative}

$\text{\tt d}(f,x)$ returns the derivative of $f$ with respect to $x$.
The $x$ can be omitted for expressions in $x$.

{\color{blue}
\begin{verbatim}
d(x^2)
\end{verbatim}
}

\noindent
$2x$

\bigskip
\noindent
The following table summarizes the various ways to obtain multi-derivatives.

\begin{center}
\begin{tabular}{cllllll}
$\displaystyle{\frac{\partial^2f}{\partial x^2}}$ & & \verb$d(f,x,x)$ & & \verb$d(f,x,2)$ \\
\\
$\displaystyle{\frac{\partial^2f}{\partial x\,\partial y}}$ & & \verb$d(f,x,y)$ \\
\\
$\displaystyle{\frac{\partial^{m+n+\cdot\cdot\cdot} f}{\partial x^m\,\partial y^n\cdots}}$ & &
\verb$d(f,x,...,y,...)$ & & \verb$d(f,x,m,y,n,...)$ \\
\end{tabular}
\end{center}

\subsection{Gradient}

The gradient of $f$ is obtained by using a vector for $x$ in $\text{\tt d}(f,x)$.

{\color{blue}
\begin{verbatim}
r = sqrt(x^2 + y^2)
d(r,(x,y))
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
{\displaystyle \frac{x}{(x^2+y^2)^{1/2}}}
\\
\\
{\displaystyle \frac{y}{(x^2+y^2)^{1/2}}}
\end{bmatrix}
$

\bigskip
\noindent
The $f$ in $\text{\tt d}(f,x)$ can be a vector or higher order function.
Gradient raises the rank by one.

{\color{blue}
\begin{verbatim}
F = (x + 2 y,3 x + 4 y)
X = (x,y)
d(F,X)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
1 & 2
\\[1ex]
3 & 4
\end{bmatrix}
$

\subsection{Template functions}

Function $f$ in $\text{\tt d}(f,x)$ does not have to be defined.
Function \verb$f$ can be a template function with just a name and an argument list.
The argument list determines the result of \verb$d$.
For example, \verb$d(f(x),x)$ evaluates to itself because $f$ depends on $x$.
However, \verb$d(f(x),y)$ evaluates to zero because $f$ does not depend on $y$.

{\color{blue}
\begin{verbatim}
d(f(x),x) -- f(x) depends on x
\end{verbatim}
}

\noindent
$\operatorname{d}(f(x),x)$

{\color{blue}
\begin{verbatim}
d(f(x),y) -- f(x) does not depend on y
\end{verbatim}
}

\noindent
$0$

{\color{blue}
\begin{verbatim}
d(f(x,y),y) -- f(x,y) depends on both x and y
\end{verbatim}
}

\noindent
$\operatorname{d}(f(x,y),y)$

{\color{blue}
\begin{verbatim}
d(f(),t) -- f() depends on all symbols
\end{verbatim}
}

\noindent
$\operatorname{d}(f(),t)$

\bigskip
\noindent
As the final example shows, an empty argument list causes
\verb$d$ to evaluate to itself, regardless
of the second argument.

\bigskip
\noindent
Template functions are useful for experimenting with differential forms.
For example, let us check the identity
$$\operatorname{div}(\operatorname{curl}{F})=0$$
for an arbitrary vector function $F$.

{\color{blue}
\begin{verbatim}
F = (F1(x,y,z),F2(x,y,z),F3(x,y,z))
div(curl(F))
\end{verbatim}
}

\noindent
$0$
